from Q1 import filter
from copy import deepcopy

NUMBERS = list(range(ord('0'), ord('9') + 1)) + [ord('.')]
OPERATORS = [ord(c) for c in "/*-+"]

def calculate(s: str) -> float:
    s = number_and_operator_filter(s)
    if not s.startswith('-'):
        s = "+" + s
    arrays = {}
    for name, char_set in zip(("numbers", "operators"), (OPERATORS, NUMBERS)):
        array = deepcopy(s)
        for c in char_set:
            array = array.replace(chr(c), ' ')
        arrays[name] = ' '.join(array.split()).strip().split(' ')
    arrays["numbers"] = [float(n) for n in arrays["numbers"]]
    stack_number = []
    stack_operator = []
    result = 0
    while len(arrays["numbers"]) > 0:
        operator = arrays["operators"].pop()
        stack_operator.append(operator)
        stack_number.append(arrays["numbers"].pop())
        if operator in "+-":
            result += calculate_stack(stack_number, stack_operator)
    return result

def number_and_operator_filter(s: str) -> str:
    return filter(s, NUMBERS + OPERATORS)

def calculate_stack(stack_number: list, stack_operator: list) -> float:
    result = 1
    while len(stack_number) > 0:
        number = stack_number.pop()
        operator = stack_operator.pop()
        if operator == '/':
            result /= number
        elif operator in "+*":
            result *= number
        elif operator == '-':
            result *= number * -1
    return result

if __name__ == "__main__":
    command = input("请输入没有括号的四则运算表达式：")
    print("结果是{:f}".format(calculate(command)))